package com.indra.bbva.pe.monitor.in.controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.indra.bbva.pe.monitor.in.bo.iface.ConsultaCargaBOIface;
import com.indra.bbva.pe.monitor.in.utils.Util;
import com.stefanini.pe.bbva.bp.monitor.in.to.MonitorOpeTO;

@Controller(value = "consultaCargaController")
@RequestScoped
public class ConsultaCargaController extends GenericoController{
	private static final Logger log = Logger.getLogger(ConsultaCargaController.class);
	
	@Autowired
	private ConsultaCargaBOIface consultaCargaBOIface;
	
	private List<MonitorOpeTO> listaLogUltimaCarga;
	
	public void onPageLoad(ComponentSystemEvent event) {
		try{
			if (!FacesContext.getCurrentInstance().isPostback()) {
				System.out.println("consultaCargaController... is not Postback");
				
				cargarDatos();
			}
		}catch(Exception e){
			log.error("Error interno. ",e);
		}
	}
	
	public void cargarDatos(){
		listaLogUltimaCarga = new ArrayList<MonitorOpeTO>();
		try {
			listaLogUltimaCarga = consultaCargaBOIface.consultaLogUltimaCarga();
		} catch (Exception e) {
			log.error("Error interno. ",e);
			mostrarError(Util.obtenerMensajeError(e));
		}
	}

	public List<MonitorOpeTO> getListaLogUltimaCarga() {
		return listaLogUltimaCarga;
	}

	public void setListaLogUltimaCarga(List<MonitorOpeTO> listaLogUltimaCarga) {
		this.listaLogUltimaCarga = listaLogUltimaCarga;
	}
}
